import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../base/base_page_widget.dart';
import '../../config/color_config.dart';
import '../../widget/my_image.dart';
import 'main_logic.dart';

class MainPage extends BasePageWidget {
  final logic = Get.find<MainLogic>();
  final state = Get.find<MainLogic>().state;

  MainPage({super.key});

  @override
  Widget initView(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: state.pageController,
        physics: const NeverScrollableScrollPhysics(),
        children: state.pages,
      ),
      bottomNavigationBar: Obx((){
        return BottomNavigationBar(
          selectedItemColor: ColorConfig.main,
          unselectedItemColor: ColorConfig.dark_text_gray,
          selectedLabelStyle: const TextStyle(color: ColorConfig.main),
          unselectedLabelStyle:
          const TextStyle(color: ColorConfig.dark_text_gray),
          currentIndex: state.selectIndex.value,
          selectedFontSize: 10,
          unselectedFontSize: 10,
          iconSize: 24,
          type: BottomNavigationBarType.fixed,
          backgroundColor: Colors.white,
          showUnselectedLabels: true,
          onTap: (int index) {
            logic.selectTabBar(index);
          },
          items: [
            BottomNavigationBarItem(
                icon: MyImage(
                    width: 24,
                    path: state.selectIndex.value == 0
                        ? state.iconSelectedList[0]
                        : state.iconList[0]),
                label: state.titles[0]),
            BottomNavigationBarItem(
                icon: MyImage(
                    width: 24,
                    path: state.selectIndex.value == 1
                        ? state.iconSelectedList[1]
                        : state.iconList[1]),
                label: state.titles[1]),
          ],
        );
      }),
    );
  }
}
